package com.kgdev.cweb.entities.prod.managed;

import java.io.Serializable;
import java.sql.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.kgdev.cweb.entities.ManagedEntity;
import com.kgdev.cweb.entities.prod.owned.order.OrderAdminParam;
import com.kgdev.cweb.entities.prod.owned.order.OrderAttributes;
import com.kgdev.cweb.entities.prod.owned.order.OrderPattern;
import com.kgdev.cweb.entities.pub.OrderStatus;

/**
 * The persistent class for the orders database table.
 * 
 */
@Entity
@NamedQueries(value = {
		@NamedQuery(name = "Order.findAll", query = "select o from Order o"),
		@NamedQuery(name = "Order.findById", query = "select o from Order o where o.orderId = :orderId"),
		@NamedQuery(name = "Order.idExists", query = "select count(o) from Order o where o.orderId = :orderId") })
@Table(name = "prod_order")
public class Order implements Serializable, ManagedEntity {

	private static final long serialVersionUID = 1L;

	@Id
	@TableGenerator(name = "PROD_ORD", allocationSize = 1, initialValue = 1, table = "SEQUENCE", valueColumnName = "SEQ_COUNT", pkColumnName = "SEQ_NAME", pkColumnValue = "PROD_ORD")
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "PROD_ORD")
	@Column(name = "order_id", unique = true, nullable = false)
	private Integer orderId;

	@Column(name = "order_name", length = 45)
	private String orderName;

	@Column(name = "order_date")
	private Date orderDate;

	@ManyToOne
	@JoinColumn(name = "status")
	private OrderStatus status;

	@OneToOne(optional = false, cascade = CascadeType.ALL)
	@JoinColumn(name = "order_id", nullable = false, insertable = false, updatable = false)
	private OrderAttributes orderAttributes;

	@OneToOne(optional = false, cascade = CascadeType.ALL)
	@JoinColumn(name = "order_id", nullable = false, insertable = false, updatable = false)
	private OrderPattern orderPattern;

	@OneToOne(optional = false, cascade = CascadeType.ALL)
	@JoinColumn(name = "order_id", nullable = false, insertable = false, updatable = false)
	private OrderAdminParam orderAdminParam;

	public OrderAdminParam getOrderAdminParam() {
		return orderAdminParam;
	}

	public void setOrderAdminParam(OrderAdminParam orderAdminParam) {
		this.orderAdminParam = orderAdminParam;
	}

	@ManyToOne
	@JoinColumn(name = "parent_order_id", nullable = false)
	private Order parentOrder;

	// bi-directional many-to-one association to Client
	@ManyToOne
	@JoinColumn(name = "client_id")
	private Client client;

	public Order() {
	}

	public Client getClient() {
		return this.client;
	}

	public OrderAttributes getOrderAttributes() {
		return orderAttributes;
	}

	public Date getOrderDate() {
		return this.orderDate;
	}

	public Integer getOrderId() {
		return this.orderId;
	}

	public String getOrderName() {
		return this.orderName;
	}

	public OrderPattern getOrderPattern() {
		return orderPattern;
	}

	public Order getParentOrder() {
		return parentOrder;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public void setOrderAttributes(OrderAttributes orderAttributes) {
		this.orderAttributes = orderAttributes;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public void setOrderId(Integer orderId) {
		this.orderId = orderId;
	}

	public void setOrderName(String orderName) {
		this.orderName = orderName;
	}

	public void setOrderPattern(OrderPattern orderPatterns) {
		this.orderPattern = orderPatterns;
	}

	public void setParentOrder(Order parentOrder) {
		this.parentOrder = parentOrder;
	}

	public OrderStatus getStatus() {
		return status;
	}

	public void setStatus(OrderStatus status) {
		this.status = status;
	}

}